#include<bits/stdc++.h>
using namespace std;

string s[200];

string decTObin(int x)
{
	string ans = "";
	while(x)
	{
		ans = to_string(x%2)+ans;
		x /= 2;
	}
	while((int)ans.size() != 5)
		ans = "0"+ans;
	return ans;
}

char mat[100][100];
char ans[100][100];

int main()
{
	s[' '] = "00000";
	for(char i = 'A';i <= 'Z';i++)
	{
		s[i] = decTObin(i-'A'+1);
//		cout<<s[i]<<endl;
	}
		
	int m, n;
	string xx;
	cin>>m>>n;
	getchar();
	getline(cin, xx);
	
	string mat = "";
	for(auto i:xx)
		mat += s[i];
	int len = mat.size();
	for(int i = len;i <= 500;i++)
		mat += "0";
//	cout<<mat<<endl<<endl;
	
	int k = -1;
	memset(ans, '*', sizeof ans);
	int x = 1, y = 0;

	while(k < len-1)
	{
		while(y+1 <= n && ans[x][y+1] == '*')
		{
			y++;
			k++;
			ans[x][y] = mat[k];
//			cout<<x<<" "<<y<<" "<<k<<endl;
			
		}
		while(x+1 <= m && ans[x+1][y] == '*')
		{
			x++;
			k++;
			ans[x][y] = mat[k];
//			cout<<x<<" "<<y<<" "<<k<<endl;
		}
		while(y-1 >= 1 && ans[x][y-1] == '*')
		{
			y--;
			k++;
			ans[x][y] = mat[k];
//			cout<<x<<" "<<y<<" "<<k<<endl;
		}
		while(x-1 >= 1 && ans[x-1][y] == '*')
		{
			x--;
			k++;
			ans[x][y] = mat[k];
//			cout<<x<<" "<<y<<" "<<k<<endl;
		}
	}
	for(int i = 1;i <= m;i++)
		for(int j = 1;j <= n;j++)
			if(ans[i][j] == '*')
				cout<<"0";
			else
				cout<<ans[i][j];
	return 0;
}

